package convert;

import com.alibaba.fastjson.JSONObject;

/**
 * Description: 构建package的工具类
 * Created by cjq on 2018/1/26
 */
public class PackageBuilder {

    private int version;

    private int action;

    private JSONObject body;

    private PackageBuilder(){}

    public static PackageBuilder newPackage(){
        return new PackageBuilder();
    }

    public PackageBuilder setVersion(int version){
        this.version = version;
        return this;
    }

    public PackageBuilder setAction(int action){
        this.action = action;
        return this;
    }

    public PackageBuilder setBody(JSONObject body){
        this.body=body;
        return this;
    }

    public ClampPackage build(){
        ClampPackage clampPackage =  new ClampPackage();
        clampPackage.setAction(action);
        clampPackage.setVersion(version);
        clampPackage.setBody(body);
        clampPackage.setSize(4 + 4 + 8 + body.toJSONString().getBytes().length);
        return clampPackage;
    }
}
